﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExamAnalysis.Model;

namespace ExamAnalysis.Controls
{
    public partial class DropDownSubjectList : System.Web.UI.UserControl
    {
        public event EventHandler SelectedSubjectChanged; //添加事件句柄
        private int _SchoolID = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindSubjectList(_SchoolID);
            }
        }
        protected void SubjectList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (SelectedSubjectChanged != null)
            {
                SelectedSubjectChanged(this, new EventArgs()); //激活SelectedClassChanged事件   
            }
        }
        protected void BindSubjectList(int schoolID)
        {
            if (_SchoolID > 0)
            {
                using (ExamAnalysisDataContext db = new ExamAnalysisDataContext())
                {
                    SubjectList.DataSource = db.SubjectInfo.Where(p => p.SchoolID == schoolID).ToList();
                    SubjectList.DataTextField = "SubjectName";
                    SubjectList.DataValueField = "SubjectID";
                    SubjectList.DataBind();
                }
            }
        }

        #region

        public Unit Width
        {
            get
            {
                return SubjectList.Width;
            }
            set
            {
                SubjectList.Width = value;
            }
        }
        public int SchoolID
        {
            get
            {
                return Convert.ToInt32(_SchoolID);
            }
            set
            {
                _SchoolID = value;
                BindSubjectList(_SchoolID);
            }
        }
        public int SubjectID
        {
            get
            {
                return Convert.ToInt32(SubjectList.SelectedValue);
            }
            set
            {
                SubjectList.SelectedValue = value.ToString();
            }
        }

        #endregion
    }
}